package org.beetl.support;

import java.util.List;
import java.util.Map;

import org.beetl.sql.core.SQLManager;

public class SqlManagerTemplate {

 protected SQLManager sqlManager;

 public SQLManager getSqlManager() {
  CommonSupport.throwIfNull(this.sqlManager, "sqlManager not allow null.");
  return sqlManager;
 }

 public void setSqlManager(SQLManager sqlManager) {
  this.sqlManager = sqlManager;
 }

 public <E> List<E> selectList(String statement, Class<E> clazz, Map<String, Object> paramMap, int offset, int limit) {
  LogSupport.logger.debug("selectList id={} params:{} offset:{} limit:{}", new Object[] { statement, paramMap, offset, limit });
  return this.getSqlManager().select(statement, clazz, paramMap, offset, limit);
 }

 public <E> List<E> selectList(String statement, Class<E> clazz, Object parameter) {
  LogSupport.logger.debug("selectList id={} params:{}", statement, parameter);
  return this.getSqlManager().select(statement, clazz, parameter);
 }

 public int insert(String statement, Object parameter) {
  LogSupport.logger.debug("insert id={} params:{}", statement, parameter);
  return this.getSqlManager().update(statement, parameter);
 }

 public int update(String statement, Object parameter) {
  LogSupport.logger.debug("update id={} params:{}", statement, parameter);
  return this.getSqlManager().update(statement, parameter);
 }

 public int delete(String statement, Object parameter) {
  LogSupport.logger.debug("delete id={} params:{}", statement, parameter);
  return this.getSqlManager().update(statement, parameter);
 }

 public int delete(String statement, Map<String, Object> parameter) {
  LogSupport.logger.debug("delete id={} params:{}", statement, parameter);
  return this.getSqlManager().update(statement, parameter);
 }

 public <E> E selectOne(String statement, Class<E> clazz, Object parameter) {
  LogSupport.logger.debug("selectOne id={} params:{}", statement, parameter);
  return this.getSqlManager().selectSingle(statement, parameter, clazz);
 }

 public <E> E selectOne(String statement, Class<E> clazz, Map<String, Object> parameter) {
  LogSupport.logger.debug("selectOne id={} params:{}", statement, parameter);
  return this.getSqlManager().selectSingle(statement, parameter, clazz);
 }

}
